import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Supermarket {
    public static void main(String[] args) {
        // 商品价格字典
        Map<Integer, Double> prices = new HashMap<>();
        prices.put(1, 8.8);
        prices.put(2, 10.0);
        prices.put(3, 18.8);
        prices.put(4, 12.5);
        prices.put(5, 15.5);

        // 初始化购物车
        Map<Integer, Integer> cart = new HashMap<>();

        Scanner scanner = new Scanner(System.in);
        char continueShopping = 0;

        do {
            System.out.println("----------小商城----------");
            System.out.println("1. 牙刷的价格为：8.8元");
            System.out.println("2. 毛巾的价格为：10.0元");
            System.out.println("3. 水杯的价格为：18.8元");
            System.out.println("4. 苹果的价格为：12.5元");
            System.out.println("5. 香蕉的价格为：15.5元");

            System.out.print("请输入你需要购买商品的序列号: ");
            int itemNumber = scanner.nextInt();

            if (itemNumber < 1 || itemNumber > 5) {
                System.out.println("无效的序列号，请重新输入。");
                continue;
            }

            System.out.print("请输入你需要购买的数量: ");
            int quantity = scanner.nextInt();

            double itemPrice = prices.get(itemNumber);
            double totalPrice = itemPrice * quantity;

            System.out.println("你购买了商品" + itemNumber + "，数量为" + quantity + "，需要花费" + totalPrice + "元");

            // 更新购物车
            cart.put(itemNumber, cart.getOrDefault(itemNumber, 0) + quantity);

            System.out.print("需要继续购买吗? (Y/N): ");
            continueShopping = scanner.next().charAt(0);
        } while (continueShopping == 'Y' || continueShopping == 'y');

        // 打印购物清单
        System.out.println("购物清单:");
        for (Map.Entry<Integer, Integer> entry : cart.entrySet()) {
            int itemNumber = entry.getKey();
            int quantity = entry.getValue();
            double itemPrice = prices.get(itemNumber);
            double totalPrice = itemPrice * quantity;
            System.out.println("商品" + itemNumber + " x " + quantity + " = " + totalPrice + "元");
        }

        System.out.println("期待您的下次光临!");
    }
}
